package com.roc.dao.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.roc.dao.DaoException;
import com.roc.dao.transReport.ITransReportDao;
import com.roc.pojo.CalcuBean;
import com.roc.pojo.Esmidinfo;
import com.roc.pojo.Operators;
import com.roc.util.Constance;

@Repository
public class TransReportDaoImpl extends BaseDaoImpl implements ITransReportDao {

	@Override
	public List<CalcuBean> queryTrans(String merchantNO, String date)
			throws DaoException {
		// TODO Auto-generated method stub
		List<CalcuBean> calcuList=new ArrayList<CalcuBean>();
		try{
			Session session = sessionFactory.getCurrentSession();
			Query query = session.createSQLQuery("select c.merno, c.etsdate, c.amount,c.merfee from t_transjnls_calcu c where c.merno='"+merchantNO+"' and c.etsdate="+date);
			List<Object> obList=query.list();
			
			for(int i=0;i<obList.size();i++){
				Iterator iterator = obList.iterator();
				while (iterator.hasNext()) {
					CalcuBean calcu = new CalcuBean();
					Object[] obj = (Object[]) iterator.next();
					calcu.setMerno(Constance.Null2EmptyTrim(obj[0]));
					calcu.setEtsdate(Constance.Null2EmptyTrim(obj[1]));
					calcu.setAmount(Double.parseDouble(Constance.null2Amt(obj[2])));
					calcu.setMerfee(Double.parseDouble(Constance.null2Amt(obj[3])));
					calcuList.add(calcu);
				}
			}
			
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			throw new DaoException("账户详情查询出错");
		}
		return calcuList;
	}

	@Override
	public Esmidinfo queryMerinfo(String merchantNo) throws DaoException {
		// TODO Auto-generated method stub
		Esmidinfo merinfo;
		try{
			Session session = sessionFactory.getCurrentSession();
			Query query = session.createQuery("from Esmidinfo m where m.mid='"+merchantNo+"'");
			merinfo=(Esmidinfo) query.uniqueResult();
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			throw new DaoException("商户详情查询出错");
		}
		return merinfo;
	}

}
